
template <class ItemType>
QueType<ItemType>::QueType()
{
	front = 0;
	rear = 0;
	maxQue = MAX_ITEMS;
	items = new ItemType[maxQue];
	if (items = NULL)
	{
		cout << "Insufficient memory to create list.\n";
		exit(1);
	}
}

template <class ItemType>
QueType<ItemType>::QueType(int max)
{
	front = 0;
	rear = 0;
	maxQue = max;
	items = new ItemType[maxQue];
	if (items = NULL)
	{
		cout << "Insufficient memory to create list.\n";
		exit(1);
	}
}

template <class ItemType>
QueType<ItemType>::QueType(const QueType& source)
{
	front = source.front;
	rear = source.rear;
	maxQue = source.maxQue;

	int position = (source.front + 1) % maxQue;
	int end = (source.rear + 1) % maxQue;
	items = new ItemType[source.maxQue];

	while(position != end)
	{
		items[position] = source.items[position];
		position = (position + 1) % maxQue;
	}
}

template <class ItemType>
QueType<ItemType>::~QueType()
{
	delete[] items;
}

template <class ItemType>
QueType<ItemType> QueType<ItemType>::operator = (const QueType& source)
{
	//check x = x case
	if (&source == this)
		return *this;

	//delete existing array in case it's not the right size
	delete[] items;

	//copy simple private variables
	front = source.front;
	back = source.back;
	maxQue = source.maxQue;

	//allocate memory for this copy
	items = new ItemType[maxQue];
	if (items == NULL)
	{
		cout << "Insufficient memory.\n";
		exit(1);
	}

	//copy contents of source array into this array
	for (int i=0; i<length; i++)
	{
		items[i] = source.items[i];
	}

	return *this;
}

template <class ItemType>
void QueType<ItemType>::MakeEmpty()
{
	front = rear;
}

template<class ItemType>
bool QueType<ItemType>::IsEmpty() const
{
	return (front == rear);
}

template<class ItemType>
bool QueType<ItemType>::IsFull() const
{
	return ((rear + 1) % maxQue == front);
}

template<class ItemType>
bool QueType<ItemType>::Enqueue(ItemType newItem)
{
	if((rear + 1) % maxQue == front)
		return false;
	rear = (rear + 1) % maxQue;
	items[rear] = newItem;
	return true;
}

template<class ItemType>
bool QueType<ItemType>::Dequeue(ItemType& item)
{
	if(front == rear)
		return false;
	front = (front + 1) % maxQue;
	item = items[front];
	return true;
}
